/*
   ScannerControl.cpp
   
   Copyright (C) 2006 LinuxOne, Inc. <Republic of korea>

   This library is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
   published by the Free Software Foundation; either version 2.1
   of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   Lessor General Public License for more details.

   You should have received a copy of the GNU Lessor General Public
   License along with this library; if not, write to the Free Software
   Foundation, inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

   Hyunjin Kim <mgc521@linuxone.co.kr>

   LinuxOne, Inc., hereby disclaims all copylight
   written by Hyunjin Kim, 20 December 2006
*/

#include <control/ScannerControl.h>

namespace booyopos
{

CScanner::CScanner()
{
	deviceControlDescription = "BooyoPOS Scanner Device Control";
	deviceControlVersion = 0;

	css= new services::CScannerService;

	CBaseControl::bs=dynamic_cast<services::CBaseService *>(css);
}

CScanner::~CScanner()
{
}

/* Capabilities */
int
CScanner::GetCapPowerReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->capPowerReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CScanner::GetCapStatisticsReporting()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->capStatisticsReporting;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CScanner::GetCapUpdateStatistics()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->capUpdateStatistics;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CScanner::GetCapCompareFirmwareVersion()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->capCompareFirmwareVersion;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CScanner::GetCapUpdateFirmware()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->capUpdateFirmware;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

/* Properties */
bool
CScanner::GetAutoDisable()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->autoDisable;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::SetAutoDisable(bool autoDisable)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->SetAutoDisable(autoDisable);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CScanner::GetDataCount()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->dataCount;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CScanner::GetDataEventEnabled()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->dataEventEnabled;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::SetDataEventEnabled(bool dataEventEnabled)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->SetDataEventEnabled(dataEventEnabled);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

bool
CScanner::GetDecodeData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->decodeData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::SetDecodeData(bool decodeData)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->SetDecodeData(decodeData);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CScanner::GetScanData()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->scanData;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

char*
CScanner::GetScanDataLabel()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->scanDataLabel;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CScanner::GetScanDataType()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->GetScanDataType();
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CScanner::GetPowerNotify()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->GetPowerNotify();
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::SetPowerNotify(int powerNotice)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->SetPowerNotify(powerNotice);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

int
CScanner::GetPowerState()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		return css->powerState;
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

/* Method */
void
CScanner::ClearInput()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->ClearInput();
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::ClearInputProperties()
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->ClearInputProperties();
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

/* statistics */
void
CScanner::ResetStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->ResetStatistics(statisticsBuffer);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::RetrieveStatistics(std::string statisticsBuffer[])
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->RetrieveStatistics(statisticsBuffer);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::UpdateStatistics(std::string statisticsBuffer)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->UpdateStatistics(statisticsBuffer);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::CompareFirmwareVersion(std::string firmwareFileName, int* result)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->CompareFirmwareVersion(firmwareFileName, result);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

void
CScanner::UpdateFirmware(std::string firmwareFileName)
throw (CByException)
{
	try
	{
		if(!bOpen)
		{
			throw CByException(E_CLOSED, "Control not opened");
		}
	
		css->UpdateFirmware(firmwareFileName);
	}
	catch(CByException bye)
	{
		throw bye;
	}
	catch(std::exception e)
	{
		throw CByException(E_CLOSED, "Unhandled exception from Device Service", e);
	}
}

} // namespace booyopos
